<?php
/**
 * Created by PhpStorm.
 * User: changshuiwang
 * Date: 2016/7/12
 * Time: 15:39
 */
namespace common\models;

use Yii;
use yii\base\Model;
use yii\web\UploadedFile;

/**
 * Login form
 */
class AddForm extends Model
{
    public $username;
    public $score;
    public $photo;

    private $_student;


    public function rules()
    {
        return [
            [['username'], 'required','on'=>['add']],
            [['username'],'match','pattern'=>'/^[a-z0-9\-_]+$/','on'=>['add']],
            [['username'], 'string', 'length'=>[4,24], 'message'=>'用户名请输入长度为2-7个字','on'=>['add']],
            [['score'], 'number', 'message'=>'分数请输入数字','on'=>['add']],
            #['photo', 'file', 'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024, 'on'=>['upload']],
            //['score','validatePhoto'],
        ];
    }

    public function scenarios()
    {
        return [
            'upload'=>['photo'],
            'add'=>['username','score','photo'],
        ];
    }

    /**
     *
     */
/*    public function reload($array){
        $this->username=$array->username;
        $this->score=$array->score;
        $this->id=$array->id;
    }*/

    /**
     *
     */
    public function validatePhoto($attribute, $params)
    {
    }

    /**
     *
     */
    public function add(){
        return Student::addStudent($this);
    }
}